import { CacheEnum } from '@/enum/CacheEnum'
import { useStore } from '@/store'
// import errorStore from '@/store/errorStore'
import { RouteLocationNormalized, Router } from 'vue-router'
import util from '@/utils/index'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

export default (router: Router) => {
  router.beforeEach(async (to, from, next) => {
    const store = useStore()

    console.log(to.path, !util.store.get(CacheEnum.TOKEN_NAME), 'auth')
    // if (to.path === '/login') { return next('/') }
    // if (!util.store.get(CacheEnum.TOKEN_NAME)) {
    //   if (to.path === '/login') { 
    //     next()
    //   } else {
    //     util.store.set(CacheEnum.REDIRECT_ROUTE_NAME, to.fullPath)
    //     console.log(222222222)
    //     return next({name: '/login'})
    //   }
    // } else {
      
    // }

    if (!to.meta?.menu?.blank) { // 是否进入历史记录
      store.layout.setNavList(to)
    }
    nprogress.start()
    next()

  })
  router.afterEach(() => {
    nprogress.done()
  })
}
